#ifndef TEACHERWINDOW_H
#define TEACHERWINDOW_H

#include <QMainWindow>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QComboBox>
#include <QSpinBox>
#include <QGroupBox>
#include <QProgressBar>
#include <QLineEdit>

// 前向声明
class ScreenRecorder;
class NetworkStreamer;
class RemoteController;
class ScreenViewer;

class TeacherWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit TeacherWindow(QWidget *parent = nullptr);
    ~TeacherWindow();

private slots:
    // 核心功能
    void startStreaming();
    void stopStreaming();
    void toggleRemoteControl();
    void applyIPSettings();
    
    // 远程控制相关槽函数
    void onRemoteControlEnabled();
    void onRemoteControlDisabled();
    void onRemoteControlEventCaptured(const QString& eventInfo);
    void onRemoteControlCommandSent(const QString& commandInfo);
    void onRemoteControlError(const QString& error);
    
    // 屏幕查看相关槽函数
    void toggleViewStudentScreen();
    void onScreenViewStarted();
    void onScreenViewStopped();
    void onScreenReceived(const QPixmap& screen);
    void onScreenViewError(const QString& error);
    
    // 屏幕控制相关槽函数
    void onStudentScreenPressed(QMouseEvent* event);
    void onStudentScreenReleased(QMouseEvent* event);
    void onStudentScreenMoved(QMouseEvent* event);
    
    // 录屏功能
    void startRecording();
    void stopRecording();
    void togglePauseRecording();
    void onRecordingModeChanged(int index);
    
    // 状态更新
    void onRecordingStatusChanged(const QString& status);
    void onRecordingDurationChanged(qint64 duration);
    void onFileSizeChanged(qint64 size);
    void onRecordingError(const QString& error);

private:
    void setupUI();
    void setupConnections();
    void updateRecordingControls();
    QString formatDuration(qint64 msecs);
    QString formatFileSize(qint64 bytes);
    
    // 事件处理
    bool eventFilter(QObject* obj, QEvent* event) override;
    QPoint convertDisplayToStudentCoordinates(const QPoint& displayPos);

private:
    // 核心功能模块
    ScreenRecorder* screenRecorder;
    NetworkStreamer* networkStreamer;
    RemoteController* remoteController;
    ScreenViewer* screenViewer;
    
    // UI组件
    QWidget* centralWidget;
    QVBoxLayout* mainLayout;
    
    // 推流控制组
    QGroupBox* streamingGroup;
    QPushButton* startButton;
    QPushButton* stopButton;
    QLabel* streamingStatusLabel;
    
    // 录屏控制组
    QGroupBox* recordingGroup;
    QComboBox* recordingModeCombo;
    QPushButton* startRecordingButton;
    QPushButton* stopRecordingButton;
    QPushButton* pauseRecordingButton;
    QLabel* recordingStatusLabel;
    QLabel* durationLabel;
    QLabel* fileSizeLabel;
    QProgressBar* recordingProgressBar;
    
    // 远程控制组
    QGroupBox* remoteControlGroup;
    QPushButton* remoteControlButton;
    QLabel* remoteControlStatusLabel;
    
    // IP配置组件
    QLineEdit* targetIPEdit;
    QSpinBox* targetPortSpinBox;
    QPushButton* applyIPButton;
    QLabel* currentIPLabel;
    
    // 屏幕显示组件
    QLabel* studentScreenLabel;
    QPushButton* viewStudentScreenButton;
    QLabel* screenViewStatusLabel;
    
    // 屏幕控制相关
    QSize studentScreenSize;  // 学生端实际屏幕尺寸
    QSize displayScreenSize;  // 显示区域尺寸
    
    // 控制变量
    bool isStreaming;
    bool isRecording;
    bool isRemoteControlEnabled;
    bool isViewingStudentScreen;
};

#endif // TEACHERWINDOW_H
